package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.service.StoreService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.param.StoreParam;
import com.tarena.lbs.pojo.basic.param.UserLocationParam;
import com.tarena.lbs.pojo.basic.query.AreaStoreQuery;
import com.tarena.lbs.pojo.basic.query.StoreQuery;
import com.tarena.lbs.pojo.basic.vo.StoreVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class StoreController {
    @Autowired
    private StoreService storeService;
    //分页列表查询 商家的店铺
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> storeList(@RequestBody StoreQuery storeQuery)
        throws BusinessException{
        return new Result<>(storeService.storeList(storeQuery));
    }
    //店铺表单新增提交
    @PostMapping("/admin/basic/store/add")
    public Result<Void> storeAdd(@RequestBody StoreParam storeParam)
        throws BusinessException{
        storeService.storeAdd(storeParam);
        return Result.success();
    }
    //根据传递的行政区域 id列表 查询满足条件的 所有店铺
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getStoreByCity
    (@RequestBody AreaStoreQuery areaStoreQuery)throws BusinessException{
        return new Result<>(storeService.storeByCity(areaStoreQuery));
    }
    //手机小程序定位上报 触发消息事件
    @PostMapping("/basic/store/location")
    public Result<Void> location(@RequestBody UserLocationParam param)
        throws BusinessException {
        storeService.location(param);
        return Result.success();
    }

}
